<template>
  <el-container class="pageWrapper">
    <el-aside width="220px">
      <div class="logo">果乐新闻管理系统</div>

      <div class="posts">文章管理</div>
      <el-menu
        class="el-menu-vertical-demo"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        :default-active="$route.path"
      >
        <el-menu-item index="/postlist" @click="goUrl('/postlist')">
          <i class="el-icon-s-order"></i>
          <span slot="title">文章列表</span>
        </el-menu-item>

        <el-menu-item index="/postpublish" @click="goUrl('/postpublish')">
          <i class="el-icon-s-promotion"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header height="100px">
        <div class="user">
          <img
            v-if="userInfo.head_img"
            :src="$axios.defaults.baseURL + userInfo.head_img"
            alt
            class="img"
          />

          <img v-else src="@/assets/logo.png" alt class="img" />
          <span>管理员：{{ userInfo.nickname }}</span>
        </div>
      </el-header>
      <el-main>

        <div class="breadcrumb">
          <span v-for="(item,index) in $route.matched" :key="index">
            {{ item.meta.name }} 
            <span v-if="index < $route.matched.length-1">/ </span>
          </span>
        </div>

        <router-view></router-view>

      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {}
    };
  },

  created() {
    const userInfo = JSON.parse(localStorage.getItem("userInfo"));

    this.userInfo = userInfo;

    console.log('本地存储的用户信息',this.userInfo);

    console.log('当前网址信息',this.$route);
  },

  methods: {
    goUrl(path) {
      if (this.$route.path != path) {
        this.$router.push(path);
      }
    }
  }
};
</script>

<style lang="less" scoped>
.pageWrapper {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}

.el-header,
.el-footer {
  background-color: #020202;
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  padding-right: 30px;
  color: #fff;
  font-family: tahoma, arial, "Hiragino Sans GB", "\5b8b\4f53", sans-serif;
  font-size: 16px;
  padding-top: -6px;

  .user {
    display: flex;
    align-items: flex-end;
    padding-bottom: 16px;

    .img {
      width: 36px;
      height: 36px;
      object-fit: cover;
      margin-right: 12px;
      border-radius: 25px;
    }

    span {
      line-height: 20px;
    }
  }
}

.el-aside {
  background-color: #232323;
  color: #fff;
  text-align: center;

  .logo {
    line-height: 100px;
    height: 100px;
    font-size: 20px;
    font-weight: 500;
    font-family: "\5b8b\4f53";
  }

  .posts {
    font-size: 18px;
    height: 50px;
    line-height: 50px;
    margin-left: -80px;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  padding: 50px 0px 100px 80px;

  .breadcrumb{
    font-weight: 700;
    font-size: 18px;
  }
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>